
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>脚手架搭建 · 《前端学习笔记》</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="XiaoChen">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-pageview-count/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-ancre-navigation/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    
    <link rel="prev" href="Web团队建设--npm私库搭建.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        <li class="header">前言</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    简介
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">Android</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../Android/Android 多包名打包应用.html">
            
                <a href="../Android/Android 多包名打包应用.html">
            
                    
                    Android 多包名打包应用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="../Android/Android UI美化之 shape的使用及其属性总结.html">
            
                <a href="../Android/Android UI美化之 shape的使用及其属性总结.html">
            
                    
                    Android UI美化之 shape的使用及其属性总结
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">ReactNative</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../ReactNative/CodePush 热更新配置及使用.html">
            
                <a href="../ReactNative/CodePush 热更新配置及使用.html">
            
                    
                    CodePush 热更新配置及使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="../ReactNative/已有Android工程 集成React Native.html">
            
                <a href="../ReactNative/已有Android工程 集成React Native.html">
            
                    
                    已有Android工程 集成React Native
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">Egret</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="../Egret/Egret 白鹭引擎参考资料.html">
            
                <a href="../Egret/Egret 白鹭引擎参考资料.html">
            
                    
                    Egret 白鹭引擎参考资料
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="../Egret/EGER PRO.html">
            
                <a href="../Egret/EGER PRO.html">
            
                    
                    EGER PRO
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="../Egret/Egret 寻路.html">
            
                <a href="../Egret/Egret 寻路.html">
            
                    
                    Egret 寻路
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">工具</li>
        
        
    
        <li class="chapter " data-level="5.1" data-path="../Tools/homebrew 使用.html">
            
                <a href="../Tools/homebrew 使用.html">
            
                    
                    homebrew 使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="../Tools/git 使用.html">
            
                <a href="../Tools/git 使用.html">
            
                    
                    git 使用
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">小程序</li>
        
        
    
        <li class="chapter " data-level="6.1" data-path="../MiniApp/Atom 完美支持 WePY 小程序开发.html">
            
                <a href="../MiniApp/Atom 完美支持 WePY 小程序开发.html">
            
                    
                    Atom 完美支持 WePY 小程序开发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="../MiniApp/Atom 插件安装慢解决方案.html">
            
                <a href="../MiniApp/Atom 插件安装慢解决方案.html">
            
                    
                    Atom 插件安装慢解决方案
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">Vue</li>
        
        
    
        <li class="chapter " data-level="7.1" data-path="../Vue2/Web 前端环境搭建.html">
            
                <a href="../Vue2/Web 前端环境搭建.html">
            
                    
                    Web 前端环境搭建
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.2" data-path="../Vue2/Vue 项目搭建.html">
            
                <a href="../Vue2/Vue 项目搭建.html">
            
                    
                    Vue 项目搭建
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.3" data-path="../Vue2/初识 VueCli 3.html">
            
                <a href="../Vue2/初识 VueCli 3.html">
            
                    
                    初识 VueCli 3
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.4" data-path="../Vue2/使用 VueCli 3.html">
            
                <a href="../Vue2/使用 VueCli 3.html">
            
                    
                    使用 VueCli 3
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.5" data-path="../Vue2/VueCli 3 项目配置.html">
            
                <a href="../Vue2/VueCli 3 项目配置.html">
            
                    
                    VueCli 3 项目配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.6" data-path="../Vue3/Vue3探索.html">
            
                <a href="../Vue3/Vue3探索.html">
            
                    
                    初识 Vue3
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">微前端</li>
        
        
    
        <li class="chapter " data-level="8.1" data-path="../MicroApp/qiankun/">
            
                <a href="../MicroApp/qiankun/">
            
                    
                    qiankun
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">团队成长</li>
        
        
    
        <li class="chapter " data-level="9.1" data-path="Web前端开发规范.html">
            
                <a href="Web前端开发规范.html">
            
                    
                    开发规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="9.2" data-path="Web团队建设--npm私库搭建.html">
            
                <a href="Web团队建设--npm私库搭建.html">
            
                    
                    私库搭建
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="9.3" data-path="Web团队建设--自定义脚手架.html">
            
                <a href="Web团队建设--自定义脚手架.html">
            
                    
                    脚手架搭建
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >脚手架搭建</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-anchor"></i><ul><li><span class="title-icon "></span><a href="#web&#x56E2;&#x961F;&#x5EFA;&#x8BBE;--&#x81EA;&#x5B9A;&#x4E49;&#x811A;&#x624B;&#x67B6;"><b></b>Web&#x56E2;&#x961F;&#x5EFA;&#x8BBE;--&#x81EA;&#x5B9A;&#x4E49;&#x811A;&#x624B;&#x67B6;</a></li><ul><li><span class="title-icon "></span><a href="#&#x6280;&#x672F;&#x9009;&#x578B;"><b></b>&#x6280;&#x672F;&#x9009;&#x578B;</a></li><ul><li><span class="title-icon "></span><a href="#&#x73AF;&#x5883;&#x8981;&#x6C42;"><b></b>&#x73AF;&#x5883;&#x8981;&#x6C42;</a></li><li><span class="title-icon "></span><a href="#&#x63D2;&#x4EF6;&#x5B89;&#x88C5;"><b></b>&#x63D2;&#x4EF6;&#x5B89;&#x88C5;</a></li></ul><li><span class="title-icon "></span><a href="#&#x601D;&#x8DEF;&#x6574;&#x7406;"><b></b>&#x601D;&#x8DEF;&#x6574;&#x7406;</a></li><ul><li><span class="title-icon "></span><a href="#&#x65B0;&#x589E;&#x6A21;&#x677F;"><b></b>&#x65B0;&#x589E;&#x6A21;&#x677F;</a></li><li><span class="title-icon "></span><a href="#&#x67E5;&#x770B;&#x6A21;&#x677F;&#x914D;&#x7F6E;"><b></b>&#x67E5;&#x770B;&#x6A21;&#x677F;&#x914D;&#x7F6E;</a></li><li><span class="title-icon "></span><a href="#&#x5220;&#x9664;&#x6A21;&#x677F;&#x914D;&#x7F6E;&#x9879;"><b></b>&#x5220;&#x9664;&#x6A21;&#x677F;&#x914D;&#x7F6E;&#x9879;</a></li><li><span class="title-icon "></span><a href="#&#x6838;&#x5FC3;&#x529F;&#x80FD;"><b></b>&#x6838;&#x5FC3;&#x529F;&#x80FD;</a></li></ul><li><span class="title-icon "></span><a href="#&#x9644;&#x8A00;"><b></b>&#x9644;&#x8A00;</a></li></ul></ul></div><a href="#web&#x56E2;&#x961F;&#x5EFA;&#x8BBE;--&#x81EA;&#x5B9A;&#x4E49;&#x811A;&#x624B;&#x67B6;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h1 id="web&#x56E2;&#x961F;&#x5EFA;&#x8BBE;--&#x81EA;&#x5B9A;&#x4E49;&#x811A;&#x624B;&#x67B6;"><a name="web&#x56E2;&#x961F;&#x5EFA;&#x8BBE;--&#x81EA;&#x5B9A;&#x4E49;&#x811A;&#x624B;&#x67B6;" class="anchor-navigation-ex-anchor" href="#web&#x56E2;&#x961F;&#x5EFA;&#x8BBE;--&#x81EA;&#x5B9A;&#x4E49;&#x811A;&#x624B;&#x67B6;"><i class="fa fa-link" aria-hidden="true"></i></a>Web&#x56E2;&#x961F;&#x5EFA;&#x8BBE;--&#x81EA;&#x5B9A;&#x4E49;&#x811A;&#x624B;&#x67B6;</h1>
<p>&#x4E00;&#x4E2A;&#x811A;&#x624B;&#x67B6;&#x5DE5;&#x5177;&#x53EF;&#x4EE5;&#x81EA;&#x52A8;&#x5316;&#x7684;&#x5E2E;&#x4F60;&#x5B8C;&#x6210;&#x4E00;&#x4E9B;&#x9879;&#x76EE;&#x57FA;&#x672C;&#x7ED3;&#x6784;&#x7684;&#x642D;&#x5EFA;&#xFF0C;&#x4ECE;&#x800C;&#x51CF;&#x8F7B;&#x65B0;&#x9879;&#x76EE;&#x7684;&#x521D;&#x59CB;&#x6210;&#x672C;&#xFF0C;&#x7C7B;&#x4F3C; <code>vue-cli</code>&#x3001;<code>create-react-app</code>&#x7B49;&#xFF0C;&#x5728;&#x6211;&#x4EEC;&#x7684;&#x5DE5;&#x4F5C;&#x8FC7;&#x7A0B;&#x4E2D;&#x603B;&#x4F1A;&#x78B0;&#x5230;&#x65B0;&#x9879;&#x76EE;&#x9700;&#x8981;&#x6CBF;&#x7528;&#x8001;&#x9879;&#x76EE;&#x7684;&#x67B6;&#x6784;&#x3001;UI&#x98CE;&#x683C;&#x7B49;&#x7C7B;&#x4F3C;&#x7684;&#x60C5;&#x51B5;&#xFF0C;&#x8FD9;&#x4E2A;&#x65F6;&#x5019;&#x6216;&#x8BB8;&#x6211;&#x4EEC;&#x5C31;&#x9700;&#x8981;&#x81EA;&#x5DF1;&#x641E;&#x4E00;&#x5957;&#x5C5E;&#x4E8E;&#x6211;&#x4EEC;&#x81EA;&#x5DF1;&#x7684;&#x811A;&#x624B;&#x67B6;&#x5DE5;&#x5177;&#x4E86;&#xFF0C;&#x63A5;&#x4E0B;&#x6765;&#x4FBF;&#x7B80;&#x5355;&#x89E3;&#x6790;&#x4E00;&#x4E2A;&#x811A;&#x624B;&#x67B6;&#x4ECE;0&#x5230;1&#x7684;&#x8FC7;&#x7A0B;&#x3002;</p>
<h2 id="&#x6280;&#x672F;&#x9009;&#x578B;"><a name="&#x6280;&#x672F;&#x9009;&#x578B;" class="anchor-navigation-ex-anchor" href="#&#x6280;&#x672F;&#x9009;&#x578B;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x6280;&#x672F;&#x9009;&#x578B;</h2>
<p>&#x8FD9;&#x91CC;&#x7531;&#x4E8E;&#x524D;&#x7AEF; <code>Node</code> &#x73AF;&#x5883;&#x90FD;&#x662F;&#x73B0;&#x6210;&#x7684;&#xFF0C;&#x53C8;&#x78B0;&#x5DE7;&#x7684; <code>Node</code> &#x53EF;&#x4EE5;&#x505A; <code>IO</code> &#x64CD;&#x4F5C;&#xFF0C;&#x6240;&#x4EE5;&#x6211;&#x4EEC;&#x7684;&#x6280;&#x672F;&#x65B9;&#x6848;&#x4FBF;&#x9009;&#x7528; <code>Node</code> &#x6765;&#x5B9E;&#x73B0;&#xFF0C;&#x5F53;&#x7136;&#x8FD8;&#x6709;&#x5F88;&#x591A;&#x5176;&#x4ED6;&#x6280;&#x672F;&#x4E5F;&#x90FD;&#x53EF;&#x4EE5;&#x9009;&#x7528;&#xFF0C;&#x7C7B;&#x4F3C; <code>Python</code> &#x7B49;&#x3002;</p>
<h3 id="&#x73AF;&#x5883;&#x8981;&#x6C42;"><a name="&#x73AF;&#x5883;&#x8981;&#x6C42;" class="anchor-navigation-ex-anchor" href="#&#x73AF;&#x5883;&#x8981;&#x6C42;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x73AF;&#x5883;&#x8981;&#x6C42;</h3>
<table>
<thead>
<tr>
<th>package</th>
<th>version</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>Node.js</code></td>
<td><code>&gt;=v12.x</code></td>
</tr>
<tr>
<td><code>npm</code></td>
<td><code>latest</code></td>
</tr>
</tbody>
</table>
<blockquote>
<p>&#x8FD9;&#x91CC;&#x5176;&#x5B9E;&#x6709;&#x597D;&#x591A;&#x7C7B;&#x5E93;&#x5B58;&#x5728;&#x66F4;&#x65B0;&#x7684;&#x7248;&#x672C;&#xFF0C;&#x4F46;&#x7531;&#x4E8E;&#x5386;&#x53F2;&#x95EE;&#x9898;&#xFF08;&#x6211;&#x8FD9;&#x4E2A;&#x811A;&#x624B;&#x67B6;&#x521B;&#x5EFA;&#x65F6;&#x95F4;&#x8F83;&#x65E9;&#xFF0C;&#x4ED3;&#x5E93;&#x8FD8;&#x4E0D;&#x80FD;&#x5B8C;&#x7F8E;&#x652F;&#x6301;&#x65B0;&#x8BED;&#x6CD5;&#xFF0C;&#x4E5F;&#x61D2;&#x5F97;&#x641E;&#xFF09;&#x8FD9;&#x91CC;&#x8FD8;&#x662F;&#x9009;&#x62E9;&#x4E86;&#x8F83;&#x8001;&#x7684;&#x7248;&#x672C;&#xFF0C;&#x540C;&#x5B66;&#x4EEC;&#x5B66;&#x4E60;&#x7684;&#x65F6;&#x5019;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x65B0;&#x7248;&#x672C;&#x6765;&#x641E;&#x3002;</p>
</blockquote>
<h3 id="&#x63D2;&#x4EF6;&#x5B89;&#x88C5;"><a name="&#x63D2;&#x4EF6;&#x5B89;&#x88C5;" class="anchor-navigation-ex-anchor" href="#&#x63D2;&#x4EF6;&#x5B89;&#x88C5;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x63D2;&#x4EF6;&#x5B89;&#x88C5;</h3>
<table>
<thead>
<tr>
<th>package</th>
<th>version</th>
<th>description</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://www.npmjs.com/package/commander/v/9.2.0" target="_blank">commander</a></td>
<td><code>^9.2.0</code></td>
<td>&#x7528;&#x6765;&#x5904;&#x7406;&#x547D;&#x4EE4;&#x884C;&#x643A;&#x5E26;&#x7684;&#x53C2;&#x6570;</td>
</tr>
<tr>
<td><a href="https://www.npmjs.com/package/chalk/v/4.1.2" target="_blank">chalk</a></td>
<td><code>^4.1.2</code></td>
<td>&#x7528;&#x4E8E;&#x5728;&#x547D;&#x4EE4;&#x884C;&#x7EC8;&#x7AEF;&#x4E2D;&#x8F93;&#x51FA;&#x5F69;&#x8272;&#x7684;&#x6587;&#x5B57;</td>
</tr>
<tr>
<td><a href="https://www.npmjs.com/package/download-git-repo/v/3.0.2" target="_blank">download-git-repo</a></td>
<td><code>^3.0.2</code></td>
<td>&#x7528;&#x4E8E;&#x4ECE; <code>git</code> &#x4ED3;&#x5E93;&#x62C9;&#x53D6;</td>
</tr>
<tr>
<td><a href="https://www.npmjs.com/package/fs-extra/v/10.1.0" target="_blank">fs-extra</a></td>
<td><code>^10.1.0</code></td>
<td>&#x7528;&#x4E8E;&#x4ECE;&#x672C;&#x5730;&#x8DEF;&#x5F84;&#x590D;&#x5236;&#x6587;&#x4EF6;&#x81F3;&#x76EE;&#x6807;&#x8DEF;&#x5F84;</td>
</tr>
<tr>
<td><a href="https://www.npmjs.com/package/handlebars/v/4.7.7" target="_blank">handlebars</a></td>
<td><code>^4.7.7</code></td>
<td>&#x6A21;&#x677F;&#x5F15;&#x64CE;&#xFF0C;&#x4F5C;&#x7528;&#x4E0D;&#x5FC5;&#x591A;&#x5C11;&#xFF0C;&#x5927;&#x5BB6;&#x5E94;&#x8BE5;&#x90FD;&#x6709;&#x6240;&#x4E86;&#x89E3;</td>
</tr>
<tr>
<td><a href="https://www.npmjs.com/package/inquirer/v/8.2.3" target="_blank">inquirer</a></td>
<td><code>^8.2.3</code></td>
<td>&#x7528;&#x4E8E;&#x7528;&#x6237;&#x4E0E;&#x547D;&#x4EE4;&#x884C;&#x4EA4;&#x4E92;</td>
</tr>
<tr>
<td><a href="https://www.npmjs.com/package/log-symbols/v/4.1.0" target="_blank">log-symbols</a></td>
<td><code>^4.1.0</code></td>
<td>&#x63D0;&#x4F9B;&#x5E26;&#x989C;&#x8272;&#x7684;&#x7B26;&#x53F7;</td>
</tr>
<tr>
<td><a href="https://www.npmjs.com/package/ora/v/5.4.1" target="_blank">ora</a></td>
<td><code>^5.4.1</code></td>
<td>&#x5B9E;&#x73B0;&#x547D;&#x4EE4;&#x884C;&#x73AF;&#x5883;&#x7684;<code>loading</code>&#x6548;&#x679C;&#xFF0C; &#x548C;&#x663E;&#x793A;&#x5404;&#x79CD;&#x72B6;&#x6001;&#x7684;&#x56FE;&#x6807;&#x7B49;</td>
</tr>
<tr>
<td><a href="https://www.npmjs.com/package/update-notifier/v/5.1.0" target="_blank">update-notifier</a></td>
<td><code>^5.1.0</code></td>
<td>&#x66F4;&#x65B0;&#x901A;&#x77E5;&#x7A0B;&#x5E8F;&#xFF0C;&#x5DE5;&#x5177;&#x5305;&#x6709;&#x66F4;&#x65B0;&#x7684;&#x8BDD;&#x63D0;&#x793A;</td>
</tr>
</tbody>
</table>
<h2 id="&#x601D;&#x8DEF;&#x6574;&#x7406;"><a name="&#x601D;&#x8DEF;&#x6574;&#x7406;" class="anchor-navigation-ex-anchor" href="#&#x601D;&#x8DEF;&#x6574;&#x7406;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x601D;&#x8DEF;&#x6574;&#x7406;</h2>
<p>&#x5F00;&#x59CB;&#x7F16;&#x7801;&#x4E4B;&#x524D;&#x5148;&#x6574;&#x7406;&#x4E00;&#x4E0B;&#x6211;&#x4EEC;&#x7684;&#x601D;&#x8DEF;&#xFF0C;&#x9996;&#x5148;&#x6211;&#x4EEC;&#x60F3;&#x8981;&#x7684;&#x529F;&#x80FD;&#x662F;&#x4ECE;&#x4E00;&#x4E2A;&#x5DF2;&#x6709;&#x7684;&#x6A21;&#x677F;&#x9879;&#x76EE;&#x76EE;&#x5F55;&#x62F7;&#x8D1D;&#x6D3E;&#x751F;&#x51FA;&#x65B0;&#x7684;&#x9879;&#x76EE;&#x4ED3;&#x5E93;&#xFF0C;&#x90A3;&#x4E48;&#x6211;&#x4EEC;&#x9996;&#x5148;&#x9700;&#x8981;&#x6709;&#x4E00;&#x4E2A;&#x6A21;&#x677F;&#x914D;&#x7F6E;&#x7684;&#x6A21;&#x5757;</p>
<h3 id="&#x65B0;&#x589E;&#x6A21;&#x677F;"><a name="&#x65B0;&#x589E;&#x6A21;&#x677F;" class="anchor-navigation-ex-anchor" href="#&#x65B0;&#x589E;&#x6A21;&#x677F;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x65B0;&#x589E;&#x6A21;&#x677F;</h3>
<p>&#x521B;&#x5EFA; <code>/command/add.js</code> &#x5E76;&#x5199;&#x5165;&#x65B0;&#x589E;&#x6A21;&#x677F;&#x7684;&#x903B;&#x8F91;&#xFF0C;&#x6B64;&#x5904;&#x6211;&#x4EEC;&#x5C06;&#x6A21;&#x677F;&#x914D;&#x7F6E;&#x4FDD;&#x5B58;&#x81F3;&#x672C;&#x5730;&#x7684;&#x4E00;&#x4E2A; <code>templates.json</code> &#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x4E2D;</p>
<pre><code class="lang-javascript"><span class="hljs-meta">&apos;use strict&apos;</span>
<span class="hljs-keyword">const</span> inquirer = <span class="hljs-built_in">require</span>(<span class="hljs-string">&quot;inquirer&quot;</span>);
<span class="hljs-keyword">const</span> config = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;../templates&apos;</span>);
<span class="hljs-keyword">const</span> {checkTemplateNameExit, templateSave, templateList, formatterAnswers} = <span class="hljs-built_in">require</span>(<span class="hljs-string">&quot;../utils/templateUtils&quot;</span>);
<span class="hljs-keyword">const</span> {InvalidArgumentError} = <span class="hljs-built_in">require</span>(<span class="hljs-string">&quot;commander&quot;</span>);
<span class="hljs-keyword">const</span> {listShowTemplates} = <span class="hljs-built_in">require</span>(<span class="hljs-string">&quot;./list&quot;</span>);
<span class="hljs-keyword">const</span> log = <span class="hljs-built_in">require</span>(<span class="hljs-string">&quot;../utils/log&quot;</span>);

<span class="hljs-keyword">const</span> templateObject = {
    name: <span class="hljs-string">&apos;&apos;</span>, <span class="hljs-comment">// &#x914D;&#x7F6E;&#x9879;&#x540D;&#x79F0;</span>
    type: <span class="hljs-string">&apos;git&apos;</span>, <span class="hljs-comment">// &#x6A21;&#x677F;&#x5DE5;&#x7A0B;&#x6765;&#x6E90;</span>
    path: <span class="hljs-string">&apos;&apos;</span>, <span class="hljs-comment">// &#x6A21;&#x677F;&#x5730;&#x5740;</span>
}

<span class="hljs-comment">/**
 * &#x65B0;&#x589E;&#x6A21;&#x677F;
 * @param template {{path: string, name: string, type: &apos;git&apos;|&apos;local&apos;}}
 * @param options {{path: string, name: string, type: &apos;git&apos;|&apos;local&apos;}}
 */</span>
<span class="hljs-keyword">const</span> addTemplate = (template = templateObject, options = templateObject) =&gt; {
    <span class="hljs-keyword">const</span> checkedObject = {
        name: options.name || template.name,
        type: options.type || template.type,
        path: options.path || template.path,
        branch: <span class="hljs-string">&apos;master&apos;</span>,
        <span class="hljs-keyword">default</span>: <span class="hljs-literal">true</span>,
    };

    checkTemplateNameExit(checkedObject.name, <span class="hljs-string">&apos;check&apos;</span>, <span class="hljs-literal">true</span>)

    <span class="hljs-keyword">const</span> buildQuestion = (value, key) =&gt; {
        <span class="hljs-keyword">return</span> <span class="hljs-string">`<span class="hljs-subst">${value &amp;&amp; &apos;Make sure&apos; || &apos;Input&apos;}</span> the <span class="hljs-subst">${key}</span> for the template`</span>
    }

    <span class="hljs-keyword">const</span> questionList = [
        {
            name: <span class="hljs-string">&apos;name&apos;</span>,
            <span class="hljs-keyword">default</span>: checkedObject.name,
            type: <span class="hljs-string">&apos;input&apos;</span>,
            message: buildQuestion(checkedObject.name, <span class="hljs-string">&apos;name&apos;</span>),
            validate: (input) =&gt; checkTemplateNameExit(input, <span class="hljs-string">&apos;inquirer&apos;</span>, <span class="hljs-literal">true</span>),
        },
        {
            type: <span class="hljs-string">&apos;list&apos;</span>,
            choices: [<span class="hljs-string">&apos;git&apos;</span>, <span class="hljs-string">&apos;local&apos;</span>],
            name: <span class="hljs-string">&apos;type&apos;</span>,
            <span class="hljs-keyword">default</span>: checkedObject.type,
            message: buildQuestion(checkedObject.type, <span class="hljs-string">&apos;type&apos;</span>),
        },
        {
            type: <span class="hljs-string">&apos;editor&apos;</span>,
            name: <span class="hljs-string">&apos;path&apos;</span>,
            <span class="hljs-keyword">default</span>: checkedObject.path,
            message: buildQuestion(checkedObject.path, <span class="hljs-string">&apos;path&apos;</span>),
            validate: (input) =&gt; {
                <span class="hljs-keyword">if</span> (!input.trim()) <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> InvalidArgumentError(<span class="hljs-string">&apos;Template path is required!&apos;</span>);
                <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
            }
        },
        {
            name: <span class="hljs-string">&apos;branch&apos;</span>,
            <span class="hljs-keyword">default</span>: <span class="hljs-string">&apos;master&apos;</span>,
            message: buildQuestion(checkedObject.branch, <span class="hljs-string">&apos;branch&apos;</span>),
            validate: (input) =&gt; {
                <span class="hljs-keyword">if</span> (!input.trim()) <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> InvalidArgumentError(<span class="hljs-string">&apos;Template branch is required!&apos;</span>);
                <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
            },
            when: (answer) =&gt; answer.type === <span class="hljs-string">&apos;git&apos;</span>
        },
        {
            type: <span class="hljs-string">&apos;confirm&apos;</span>,
            name: <span class="hljs-string">&apos;default&apos;</span>,
            <span class="hljs-keyword">default</span>: <span class="hljs-literal">true</span>,
            message: <span class="hljs-string">&apos;Do you want to set it as the default option&apos;</span>
        }
    ];

    inquirer
        .prompt(questionList)
        .then(answers =&gt; {

            formatterAnswers(answers);

            <span class="hljs-keyword">if</span> (answers.default) {
                templateList().forEach(item =&gt; item.default = <span class="hljs-literal">false</span>);
            }

            config.tpl[answers.name] = {...answers, path: answers.path.replace(<span class="hljs-regexp">/[\u0000-\u0019]/g</span>, <span class="hljs-string">&apos;&apos;</span>)};

            templateSave(config).then(() =&gt; {
                log.log(<span class="hljs-string">&apos;\n&apos;</span>);
                log.success(<span class="hljs-string">&apos;New template added!\n&apos;</span>);
                log.info(<span class="hljs-string">&apos;The last template list is: \n&apos;</span>)
                listShowTemplates();
                log.log(<span class="hljs-string">&apos;\n&apos;</span>)
                process.exit()
            }).catch(() =&gt; {
                process.exit()
            })
        })
        .catch((error) =&gt; {
            <span class="hljs-keyword">if</span> (error.isTtyError) {
                log.error(<span class="hljs-string">`Prompt couldn&apos;t be rendered in the current environment`</span>)
            } <span class="hljs-keyword">else</span> {
                log.error(error)
            }
        })
}

<span class="hljs-built_in">module</span>.exports = {
    addTemplate,
}
</code></pre>
<h3 id="&#x67E5;&#x770B;&#x6A21;&#x677F;&#x914D;&#x7F6E;"><a name="&#x67E5;&#x770B;&#x6A21;&#x677F;&#x914D;&#x7F6E;" class="anchor-navigation-ex-anchor" href="#&#x67E5;&#x770B;&#x6A21;&#x677F;&#x914D;&#x7F6E;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x67E5;&#x770B;&#x6A21;&#x677F;&#x914D;&#x7F6E;</h3>
<p>&#x65B0;&#x589E; <code>/command/list.js</code> &#x6587;&#x4EF6;&#xFF0C;&#x8BFB;&#x53D6;&#x5E76;&#x8F93;&#x51FA;&#x6A21;&#x677F;&#x914D;&#x7F6E;&#x5217;&#x8868;</p>
<pre><code class="lang-javascript"><span class="hljs-meta">&apos;use strict&apos;</span>
<span class="hljs-keyword">const</span> {showLogo, templateList} = <span class="hljs-built_in">require</span>(<span class="hljs-string">&quot;../utils/templateUtils&quot;</span>);
<span class="hljs-keyword">const</span> log = <span class="hljs-built_in">require</span>(<span class="hljs-string">&quot;../utils/log&quot;</span>);

<span class="hljs-keyword">const</span> listShowTemplates = (withLogo) =&gt; {
    withLogo &amp;&amp; showLogo();
    log.table(templateList())
    process.exit()
}

<span class="hljs-built_in">module</span>.exports = {
    listShowTemplates,
}
</code></pre>
<h3 id="&#x5220;&#x9664;&#x6A21;&#x677F;&#x914D;&#x7F6E;&#x9879;"><a name="&#x5220;&#x9664;&#x6A21;&#x677F;&#x914D;&#x7F6E;&#x9879;" class="anchor-navigation-ex-anchor" href="#&#x5220;&#x9664;&#x6A21;&#x677F;&#x914D;&#x7F6E;&#x9879;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5220;&#x9664;&#x6A21;&#x677F;&#x914D;&#x7F6E;&#x9879;</h3>
<p>&#x65B0;&#x589E; <code>/command/delete.js</code> &#x6587;&#x4EF6;&#xFF0C;&#x5E76;&#x5199;&#x5165;&#x79FB;&#x9664;&#x6A21;&#x677F;&#x7684;&#x903B;&#x8F91;</p>
<pre><code class="lang-javascript"><span class="hljs-meta">&apos;use strict&apos;</span>
<span class="hljs-keyword">const</span> config = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;../templates&apos;</span>)
<span class="hljs-keyword">const</span> inquirer = <span class="hljs-built_in">require</span>(<span class="hljs-string">&quot;inquirer&quot;</span>);
<span class="hljs-keyword">const</span> {checkTemplateNameExit, templateSave, templateNameList, formatterAnswers} = <span class="hljs-built_in">require</span>(<span class="hljs-string">&quot;../utils/templateUtils&quot;</span>);
<span class="hljs-keyword">const</span> {listShowTemplates} = <span class="hljs-built_in">require</span>(<span class="hljs-string">&quot;./list&quot;</span>);
<span class="hljs-keyword">const</span> log = <span class="hljs-built_in">require</span>(<span class="hljs-string">&quot;../utils/log&quot;</span>);

<span class="hljs-keyword">const</span> removeTemplate = (name = <span class="hljs-string">&apos;&apos;</span>) =&gt; {
    inquirer
        .prompt([
            {
                type: <span class="hljs-string">&apos;input&apos;</span>,
                name: <span class="hljs-string">&apos;name&apos;</span>,
                <span class="hljs-keyword">default</span>: name,
                message: <span class="hljs-string">`<span class="hljs-subst">${name ? &apos;Is&apos; : &apos;Input&apos;}</span> the template name`</span>,
                validate: (input) =&gt; checkTemplateNameExit(input, <span class="hljs-string">&apos;inquirer&apos;</span>, <span class="hljs-literal">false</span>, <span class="hljs-string">&apos;exit&apos;</span>)
            },
            {
                type: <span class="hljs-string">&apos;confirm&apos;</span>,
                name: <span class="hljs-string">&apos;confirm&apos;</span>,
                message: <span class="hljs-string">&apos;Confirm to remove this template&apos;</span>,
                <span class="hljs-keyword">default</span>: <span class="hljs-literal">true</span>
            },
        ])
        .then((answers) =&gt; {
            <span class="hljs-keyword">if</span> (answers.confirm) {

                formatterAnswers(answers);

                <span class="hljs-keyword">if</span> (templateNameList().length &gt; <span class="hljs-number">1</span>) {
                    <span class="hljs-keyword">delete</span> config.tpl[answers.name];
                    templateSave(config).then(() =&gt; {
                        log.log(<span class="hljs-string">&apos;\n&apos;</span>);
                        log.success(<span class="hljs-string">&apos;Template removed!\n&apos;</span>)
                        log.info(<span class="hljs-string">&apos;The last template list is: \n&apos;</span>)
                        listShowTemplates();
                        log.log(<span class="hljs-string">&apos;\n&apos;</span>);
                        process.exit();
                    }).catch(() =&gt; {
                        process.exit();
                    })
                } <span class="hljs-keyword">else</span> {
                    log.error(<span class="hljs-string">&apos;At least one template needs to be retained!\n&apos;</span>);
                    process.exit();
                }
            } <span class="hljs-keyword">else</span> {
                log.warning(<span class="hljs-string">&apos;The operation was cancelled!\n&apos;</span>)
                process.exit()
            }
        })
        .catch((error) =&gt; {
            <span class="hljs-keyword">if</span> (error.isTtyError) {
                log.error(<span class="hljs-string">`Prompt couldn&apos;t be rendered in the current environment`</span>)
            } <span class="hljs-keyword">else</span> {
                log.error(error)
            }
        })
}

<span class="hljs-built_in">module</span>.exports = {
    removeTemplate,
}
</code></pre>
<h3 id="&#x6838;&#x5FC3;&#x529F;&#x80FD;"><a name="&#x6838;&#x5FC3;&#x529F;&#x80FD;" class="anchor-navigation-ex-anchor" href="#&#x6838;&#x5FC3;&#x529F;&#x80FD;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x6838;&#x5FC3;&#x529F;&#x80FD;</h3>
<p>&#x5173;&#x4E8E;&#x6A21;&#x677F;&#x7684;&#x529F;&#x80FD;&#x6211;&#x4EEC;&#x5DF2;&#x7ECF;&#x6DFB;&#x52A0;&#x8FC7;&#x4E86;&#xFF0C; &#x63A5;&#x4E0B;&#x6765;&#x4FBF;&#x5F00;&#x59CB;&#x5B9E;&#x73B0;&#x6211;&#x4EEC;&#x7684;&#x6838;&#x5FC3;&#x529F;&#x80FD;&#xFF0C;&#x901A;&#x8FC7;&#x63A5;&#x6536;&#x7528;&#x6237;&#x8F93;&#x5165;&#x7684;&#x9879;&#x76EE;&#x914D;&#x7F6E;&#x53C2;&#x6570;&#x6765;&#x901A;&#x8FC7;&#x6A21;&#x677F;&#x5DE5;&#x7A0B;&#x521B;&#x5EFA;&#x6211;&#x4EEC;&#x60F3;&#x8981;&#x7684;&#x65B0;&#x9879;&#x76EE;&#x3002;</p>
<p>&#x6DFB;&#x52A0; <code>/command/init.js</code> &#x6587;&#x4EF6;&#xFF0C;&#x5E76;&#x5199;&#x5165;&#x4EE5;&#x4E0B;&#x5185;&#x5BB9;</p>
<pre><code class="lang-javascript"><span class="hljs-meta">&apos;use strict&apos;</span>
<span class="hljs-keyword">const</span> config = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;../templates&apos;</span>)
<span class="hljs-keyword">const</span> inquirer = <span class="hljs-built_in">require</span>(<span class="hljs-string">&quot;inquirer&quot;</span>);
<span class="hljs-keyword">const</span> os = <span class="hljs-built_in">require</span>(<span class="hljs-string">&quot;os&quot;</span>);
<span class="hljs-keyword">const</span> fsExtra = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;fs-extra&apos;</span>);
<span class="hljs-keyword">const</span> {InvalidArgumentError} = <span class="hljs-built_in">require</span>(<span class="hljs-string">&quot;commander&quot;</span>);
<span class="hljs-keyword">const</span> download = <span class="hljs-built_in">require</span>(<span class="hljs-string">&quot;download-git-repo&quot;</span>);
<span class="hljs-keyword">const</span> handlebars = <span class="hljs-built_in">require</span>(<span class="hljs-string">&quot;handlebars&quot;</span>);
<span class="hljs-keyword">const</span> ora = <span class="hljs-built_in">require</span>(<span class="hljs-string">&quot;ora&quot;</span>);
<span class="hljs-keyword">const</span> {getTemplateDefault, templateNameList, showLogo, formatterAnswers} = <span class="hljs-built_in">require</span>(<span class="hljs-string">&quot;../utils/templateUtils&quot;</span>);
<span class="hljs-keyword">const</span> log = <span class="hljs-built_in">require</span>(<span class="hljs-string">&quot;../utils/log&quot;</span>);

<span class="hljs-keyword">const</span> createSuccess = (spinner, projectConfig) =&gt; {
    spinner.succeed();
    <span class="hljs-comment">// &#x6A21;&#x677F;&#x6587;&#x4EF6;&#x5217;&#x8868;</span>
    <span class="hljs-keyword">const</span> fileName = [
        <span class="hljs-string">`<span class="hljs-subst">${projectConfig.name}</span>/package.json`</span>,
        <span class="hljs-string">`<span class="hljs-subst">${projectConfig.name}</span>/index.html`</span>
    ];
    <span class="hljs-keyword">const</span> removeFiles = [
        <span class="hljs-string">`<span class="hljs-subst">${projectConfig.name}</span>/.git`</span>
    ]
    <span class="hljs-keyword">const</span> meta = {
        name: projectConfig.name,
        version: projectConfig.version,
        description: projectConfig.description,
        author: projectConfig.author
    }
    fileName.forEach(item =&gt; {
        <span class="hljs-keyword">if</span> (fsExtra.pathExistsSync(item)) {
            <span class="hljs-keyword">const</span> content = fsExtra.readFileSync(item).toString();
            <span class="hljs-keyword">const</span> result = handlebars.compile(content)(meta);
            fsExtra.outputFileSync(item, result);
        }
    });
    <span class="hljs-comment">// &#x5220;&#x9664;&#x591A;&#x4F59;&#x6587;&#x4EF6;</span>
    removeFiles.forEach(item =&gt; {
        fsExtra.removeSync(item);
    })

    showLogo();
    log.success(<span class="hljs-string">`Successfully created project <span class="hljs-subst">${projectConfig.name}</span>.`</span>)
    log.success(<span class="hljs-string">&apos;Get started with the following commands:\n&apos;</span>)
    log.bash(<span class="hljs-string">`cd <span class="hljs-subst">${projectConfig.name}</span> &amp;&amp; npm install`</span>)
}

<span class="hljs-keyword">const</span> createProjectFromGit = (projectConfig) =&gt; {
    <span class="hljs-keyword">const</span> spinner = ora(<span class="hljs-string">&apos;Download from template...&apos;</span>);
    spinner.start();
    download(<span class="hljs-string">`direct:<span class="hljs-subst">${projectConfig.template.path}</span>#<span class="hljs-subst">${projectConfig.template.branch}</span>`</span>, projectConfig.name, {clone: <span class="hljs-literal">true</span>}, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">err</span>) </span>{
        <span class="hljs-keyword">if</span> (err) {
            spinner.fail();
            log.error(err)
        } <span class="hljs-keyword">else</span> {
            createSuccess(spinner, projectConfig)
        }
        process.exit();
    })
}

<span class="hljs-keyword">const</span> createProjectFromLocal = (projectConfig) =&gt; {
    <span class="hljs-keyword">const</span> spinner = ora(<span class="hljs-string">&apos;Creating from template...&apos;</span>);
    spinner.start();
    fsExtra.copy(projectConfig.template.path.trim(), <span class="hljs-string">`./<span class="hljs-subst">${projectConfig.name}</span>`</span>)
        .then(() =&gt; {
            createSuccess(spinner, projectConfig)
            process.exit();
        })
        .catch(err =&gt; {
            spinner.fail()
            log.error(err)
            process.exit();
        })
}

<span class="hljs-keyword">const</span> initProjectFromTemplate = (projectName = <span class="hljs-string">&apos;my-app&apos;</span>, templateName = <span class="hljs-string">&apos;&apos;</span>) =&gt; {
    inquirer.prompt([
        {
            type: <span class="hljs-string">&apos;input&apos;</span>,
            name: <span class="hljs-string">&apos;projectName&apos;</span>,
            <span class="hljs-keyword">default</span>: projectName,
            message: <span class="hljs-string">&apos;Is sure the project name&apos;</span>,
            validate: (input) =&gt; {
                <span class="hljs-keyword">if</span> (!input) <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> InvalidArgumentError(<span class="hljs-string">&apos;project name is required!&apos;</span>);
                <span class="hljs-keyword">if</span> (fsExtra.pathExistsSync(input)) <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> InvalidArgumentError(<span class="hljs-string">&apos;directory already exists!&apos;</span>);
                <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>
            }
        },
        {
            name: <span class="hljs-string">&apos;version&apos;</span>,
            <span class="hljs-keyword">default</span>: <span class="hljs-string">&apos;1.0.0&apos;</span>,
            message: <span class="hljs-string">&apos;input the project version&apos;</span>
        },
        {
            name: <span class="hljs-string">&apos;description&apos;</span>,
            <span class="hljs-keyword">default</span>: projectName,
            message: <span class="hljs-string">&apos;input the project description&apos;</span>
        },
        {
            name: <span class="hljs-string">&apos;author&apos;</span>,
            <span class="hljs-keyword">default</span>: os.userInfo().username,
            message: <span class="hljs-string">&apos;input the project author&apos;</span>
        },
        {
            type: <span class="hljs-string">&apos;confirm&apos;</span>,
            name: <span class="hljs-string">&apos;defaultTemplate&apos;</span>,
            message: <span class="hljs-string">&apos;use the default template&apos;</span>,
            when: !templateName
        },
        {
            type: <span class="hljs-string">&apos;list&apos;</span>,
            name: <span class="hljs-string">&apos;templateName&apos;</span>,
            <span class="hljs-keyword">default</span>: templateNameList()[<span class="hljs-number">0</span>],
            choices: templateNameList(),
            when: (answers) =&gt; {
                <span class="hljs-keyword">if</span> (!templateName) <span class="hljs-keyword">return</span> !answers.defaultTemplate;
                <span class="hljs-keyword">else</span> <span class="hljs-keyword">return</span> !templateNameList().some(item =&gt; item === templateName);
            },
            message: <span class="hljs-string">&apos;choose the project template&apos;</span>,
        },
    ]).then(answers =&gt; {

        formatterAnswers(answers);

        <span class="hljs-keyword">const</span> {projectName, version, description, author} = answers;

        <span class="hljs-keyword">let</span> template = answers.templateName || templateName;

        <span class="hljs-keyword">if</span> (answers.defaultTemplate) template = getTemplateDefault().name;

        <span class="hljs-keyword">const</span> projectConfig = {name: projectName, version, description, author, template: config.tpl[template]}

        <span class="hljs-keyword">switch</span> (projectConfig.template.type) {
            <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;git&apos;</span>:
                createProjectFromGit(projectConfig);
                <span class="hljs-keyword">break</span>;
            <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;local&apos;</span>:
                createProjectFromLocal(projectConfig);
                <span class="hljs-keyword">break</span>;
            <span class="hljs-keyword">default</span>:
                log.warning(<span class="hljs-string">&apos;Type not supported yet!&apos;</span>);
                process.exit();
        }
    }).catch(err =&gt; {
        log.error(err)
        process.exit()
    })
}

<span class="hljs-built_in">module</span>.exports = {
    initProjectFromTemplate
}
</code></pre>
<p>&#x6700;&#x540E;&#x518D;&#x914D;&#x7F6E;&#x4E0B;&#x6211;&#x4EEC;&#x7684;&#x5165;&#x53E3;&#x6587;&#x4EF6;&#xFF0C;&#x65B0;&#x589E; <code>/bin/sim.js</code> &#x5E76;&#x6CE8;&#x518C;&#x6211;&#x4EEC;&#x7684;&#x547D;&#x4EE4;&#x9879;</p>
<pre><code class="lang-javascript"><span class="hljs-meta">#!/usr/bin/env node --harmony</span>
<span class="hljs-meta">&apos;use strict&apos;</span>
<span class="hljs-keyword">const</span> { program } = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;commander&apos;</span>);
<span class="hljs-keyword">const</span> pkg = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;../package.json&apos;</span>)
<span class="hljs-keyword">const</span> updateNotifier = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;update-notifier&apos;</span>)
<span class="hljs-keyword">const</span> {addTemplate, removeTemplate, listShowTemplates, initProjectFromTemplate} = <span class="hljs-built_in">require</span>(<span class="hljs-string">&quot;../command&quot;</span>);
<span class="hljs-keyword">const</span> {checkTemplateType, showLogo} = <span class="hljs-built_in">require</span>(<span class="hljs-string">&quot;../utils/templateUtils&quot;</span>);
updateNotifier({ pkg }).notify({ isGlobal: <span class="hljs-literal">true</span> })

program
    .version(pkg.version, <span class="hljs-string">&apos;-v, --version&apos;</span>)
    .option(<span class="hljs-string">&apos;-a, --add [name...]&apos;</span>, <span class="hljs-string">&apos;Create a new project template&apos;</span>)
    .option(<span class="hljs-string">&apos;-r, --remove [name...]&apos;</span>, <span class="hljs-string">&apos;Remove a template&apos;</span>)
    .option(<span class="hljs-string">&apos;-l, --list&apos;</span>, <span class="hljs-string">&apos;List all of project templates&apos;</span>)
    .option(<span class="hljs-string">&apos;-i, --init [name...]&apos;</span>, <span class="hljs-string">&apos;Build a new project from template&apos;</span>)
    .usage(<span class="hljs-string">&apos;&lt;command&gt; [options]&apos;</span>)
    .description(<span class="hljs-string">&apos;Build a new project based on the project template&apos;</span>)
    .action((options) =&gt; {
        <span class="hljs-keyword">if</span> (options.add) addTemplate({name: options.add[<span class="hljs-number">0</span>], type: options.add[<span class="hljs-number">1</span>], path: options.add[<span class="hljs-number">2</span>]});
        <span class="hljs-keyword">if</span> (options.remove) removeTemplate(options.remove[<span class="hljs-number">0</span>]);
        <span class="hljs-keyword">if</span> (options.list) listShowTemplates(<span class="hljs-literal">true</span>);
        <span class="hljs-keyword">if</span> (options.init) initProjectFromTemplate(options.init[<span class="hljs-number">0</span>], options.init[<span class="hljs-number">1</span>]);
    })

program
    .command(<span class="hljs-string">&apos;add&apos;</span>)
    .argument(<span class="hljs-string">&apos;[name]&apos;</span>, <span class="hljs-string">&apos;the template name&apos;</span>, <span class="hljs-string">&apos;&apos;</span>)
    .argument(<span class="hljs-string">&apos;[type]&apos;</span>, <span class="hljs-string">&apos;the template type of git or local&apos;</span>, checkTemplateType, <span class="hljs-string">&apos;&apos;</span>)
    .argument(<span class="hljs-string">&apos;[path]&apos;</span>, <span class="hljs-string">&apos;the template path for gitUrl or localPath&apos;</span>, <span class="hljs-string">&apos;&apos;</span>)
    .option(<span class="hljs-string">&apos;-n, --name &lt;name&gt;&apos;</span>, <span class="hljs-string">&apos;the template name&apos;</span>, <span class="hljs-string">&apos;&apos;</span>)
    .option(<span class="hljs-string">&apos;-t, --type &lt;type&gt;&apos;</span>, <span class="hljs-string">&apos;the template type of git or local&apos;</span>, checkTemplateType, <span class="hljs-string">&apos;&apos;</span>)
    .option(<span class="hljs-string">&apos;-p, --path &lt;path&gt;&apos;</span>, <span class="hljs-string">&apos;the template path for git or local&apos;</span>, <span class="hljs-string">&apos;&apos;</span>)
    .description(<span class="hljs-string">&apos;Create a new project template&apos;</span>)
    .action((name, type, path, options) =&gt; {addTemplate({name, type, path}, options)})

program
    .command(<span class="hljs-string">&apos;remove&apos;</span>)
    .argument(<span class="hljs-string">&apos;[name]&apos;</span>, <span class="hljs-string">&apos;the template name&apos;</span>, <span class="hljs-string">&apos;&apos;</span>)
    .option(<span class="hljs-string">&apos;-n, --name &lt;name&gt;&apos;</span>, <span class="hljs-string">&apos;the template name&apos;</span>, <span class="hljs-string">&apos;&apos;</span>)
    .description(<span class="hljs-string">&apos;Remove a template&apos;</span>)
    .action((name, options) =&gt; {removeTemplate(name || options.name)})

program
    .command(<span class="hljs-string">&apos;list&apos;</span>)
    .description(<span class="hljs-string">&apos;List all of project templates&apos;</span>)
    .action(() =&gt; listShowTemplates(<span class="hljs-literal">true</span>))

program
    .command(<span class="hljs-string">&apos;init&apos;</span>)
    .description(<span class="hljs-string">&apos;Build a new project from a template&apos;</span>)
    .argument(<span class="hljs-string">&apos;[projectName]&apos;</span>, <span class="hljs-string">&apos;the project name&apos;</span>, <span class="hljs-string">&apos;&apos;</span>)
    .argument(<span class="hljs-string">&apos;[templateName]&apos;</span>, <span class="hljs-string">&apos;the template name&apos;</span>, <span class="hljs-string">&apos;&apos;</span>)
    .option(<span class="hljs-string">&apos;-p, --projectName &lt;name&gt;&apos;</span>, <span class="hljs-string">&apos;the project name&apos;</span>, <span class="hljs-string">&apos;&apos;</span>)
    .option(<span class="hljs-string">&apos;-t, --templateName &lt;name&gt;&apos;</span>, <span class="hljs-string">&apos;the template name&apos;</span>, <span class="hljs-string">&apos;&apos;</span>)
    .action((projectName, templateName, options) =&gt; {
        initProjectFromTemplate(options.projectName || projectName, options.templateName || templateName)
    })

program.parse(process.argv);

<span class="hljs-keyword">if</span> (!program.args.length &amp;&amp; !<span class="hljs-built_in">Object</span>.keys(program.opts()).length) {
    showLogo()
    program.help()
}
</code></pre>
<p>&#x63A5;&#x4E0B;&#x6765;&#x4FBF;&#x628A;&#x6211;&#x4EEC;&#x7684;&#x5DE5;&#x7A0B;&#x901A;&#x8FC7; <code>npm publish</code> &#x547D;&#x4EE4;&#x53D1;&#x5E03;&#x5230; <code>npm</code> &#x670D;&#x52A1;&#x5668;&#x7136;&#x540E;&#x5C31;&#x53EF;&#x4EE5;&#x5206;&#x4EAB;&#x7ED9;&#x5C0F;&#x4F19;&#x4F34;&#x4EEC;&#x4F7F;&#x7528;&#x4E86;</p>
<h2 id="&#x9644;&#x8A00;"><a name="&#x9644;&#x8A00;" class="anchor-navigation-ex-anchor" href="#&#x9644;&#x8A00;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x9644;&#x8A00;</h2>
<p>&#x9644;&#x4E0A;&#x9879;&#x76EE;&#x53C2;&#x8003;&#x8D44;&#x6599;&#xFF0C;&#x4EE5;&#x4F9B;&#x5C0F;&#x4F19;&#x4F34;&#x4EEC;&#x53C2;&#x8003;</p>
<p><a href="https://github.com/ChenZengQing/sim-vue-cli" target="_blank">&#x4EE3;&#x7801;&#x4ED3;&#x5E93;&#x5730;&#x5740;</a></p>
<p><a href="https://www.npmjs.com/package/sim-vue" target="_blank">sim-vue</a></p>
<footer class="page-footer"><span class="copyright">Copyright &amp; copy zengqing.top 2023 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x66F4;&#x65B0;&#x4E8E;&#xFF1A;
2022-09-18 23:02:35
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="Web团队建设--npm私库搭建.html" class="navigation navigation-prev navigation-unique" aria-label="Previous page: 私库搭建">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"脚手架搭建","level":"9.3","depth":1,"previous":{"title":"私库搭建","level":"9.2","depth":1,"path":"Team/Web团队建设--npm私库搭建.md","ref":"./Team/Web团队建设--npm私库搭建.md","articles":[]},"dir":"ltr"},"config":{"plugins":["expandable-chapters","code","pageview-count","chapter-fold","expandable-chapters-small","tbfed-pagefooter","hide-element","ancre-navigation"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright & copy zengqing.top 2023","modify_label":"该文件更新于：","modify_format":"YYYY-MM-DD HH:mm:ss"},"chapter-fold":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"code":{"copyButtons":true},"hide-element":{"elements":[".gitbook-link"]},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"pageview-count":{},"ancre-navigation":{"showLevel":true,"associatedWithSummary":true,"mode":"float","printLog":false,"multipleH1":true,"float":{"showLevelIcon":false,"level1Icon":"","level2Icon":"","level3Icon":""},"pageTop":{"showLevelIcon":false,"level1Icon":"","level2Icon":"","level3Icon":""}},"expandable-chapters-small":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{}},"theme":"default","author":"XiaoChen","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"《前端学习笔记》","language":"zh-hans","gitbook":"*","description":"个人学习笔记，记录学习过程中的点点滴滴"},"file":{"path":"Team/Web团队建设--自定义脚手架.md","mtime":"2022-09-18T15:02:35.058Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2023-03-26T04:06:26.355Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-pageview-count/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-hide-element/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

